package com.testMgmt.controller;

import io.swagger.annotations.Api;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/test")
@Api("测试相关接口")
public class TestController {

    @Resource(name = "ehCacheCacheManager")
    private CacheManager ehCacheCacheManager;

    @RequestMapping(path = "/user", method = RequestMethod.GET)
    public String getEhCache(@RequestParam String userID) {
        String userCacheKey = "sampleCache1";
        Cache userCache = ehCacheCacheManager.getCache(userCacheKey);
        String userInfoCacheKey = userCacheKey + ":" + userID;
        userCache.putIfAbsent(userInfoCacheKey, "james");
        return userCache.get(userInfoCacheKey, String.class);
    }
}
